package com.synjones.wschool.face.service.request;

import com.synjones.wschool.common.exception.BizException;
import com.synjones.wschool.common.exception.ValidateException;
import com.synjones.wschool.face.constant.UserSourceEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.context.annotation.Bean;

import java.util.Arrays;
import java.util.List;

/**
 * Created by 24398 on 2018/8/2.
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class GateInfoUserAddReq extends BaseReq {
    List<InnerGateInfo> innerGateInfos;

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class InnerGateInfo{
        private String gateNO;
        private Integer    userSourceId;
    }

    public void checkParam(){

        List<Integer> checkUserTypes = Arrays.asList(new Integer[]{UserSourceEnum.TEACHER.getUserSourceId(),
                    UserSourceEnum.GUARDIAN.getUserSourceId(),UserSourceEnum.STUDENT.getUserSourceId()});

        if(this.innerGateInfos == null || this.innerGateInfos.isEmpty()){
             throw new ValidateException("闸机信息不能为空");
        }

        innerGateInfos.forEach(innerGateInfo -> {
            if(!checkUserTypes.parallelStream().anyMatch(checkUserType -> checkUserType.equals(innerGateInfo.getUserSourceId()))){
                 throw new ValidateException("userSourceId 参数不合法");
            }
        });

    }



}
